home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Sound / A-Law sdec⁄scom / ComponentDispatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-18  |  4.6 KB  |  143 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Common routines for dispatching for any sound component
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    ComponentDispatch.c
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include "ComponentDispatch.h"
  23.  
  24. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. //    Sound Component Entry Point
  26. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27.  
  28. #if !GENERATINGPOWERPC
  29. pascal ComponentResult SoundComponentEntryPoint(ComponentParameters *params, SoundComponentGlobalsPtr globals);
  30. pascal ComponentResult SoundComponentEntryPoint(ComponentParameters *params, SoundComponentGlobalsPtr globals)
  31. #else
  32. static pascal ComponentResult SoundComponentProc(ComponentParameters *params, SoundComponentGlobalsPtr globals);
  33. RoutineDescriptor SoundComponentEntryPoint = BUILD_ROUTINE_DESCRIPTOR(uppSoundComponentEntryPointProcInfo, SoundComponentProc);
  34. static pascal ComponentResult SoundComponentProc(ComponentParameters *params, SoundComponentGlobalsPtr globals)
  35. #endif
  36. {
  37.     ComponentResult                result;
  38.     short                        selector = params->what;
  39.  
  40.     if (selector < 0)
  41.         switch (selector - kComponentRegisterSelect)    // standard component selectors
  42.         {
  43.             case kComponentRegisterSelect - kComponentRegisterSelect:
  44.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentRegister);
  45.                 break;
  46.  
  47.             case kComponentVersionSelect - kComponentRegisterSelect:
  48.                 return (kSoundComponentVersion);
  49.                 break;
  50.  
  51.             case kComponentCanDoSelect - kComponentRegisterSelect:
  52.                 result = __SoundComponentCanDo(0, *((short *) ¶ms->params[0]));
  53.                 break;
  54.  
  55.             case kComponentCloseSelect - kComponentRegisterSelect:
  56.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentClose);
  57.                 break;
  58.  
  59.             case kComponentOpenSelect - kComponentRegisterSelect:
  60.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentOpen);
  61.                 break;
  62.  
  63.             default:
  64.                 result = badComponentSelector;
  65.                 break;
  66.         }
  67.     else if (selector < kDelegatedSoundComponentSelectors)            // selectors that cannot be delegated
  68.         switch (selector)
  69.         {
  70.             case kSoundComponentSetSourceSelect:
  71.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentSetSource);
  72.                 break;
  73.  
  74.             case kSoundComponentGetSourceDataSelect:
  75.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentGetSourceData);
  76.                 break;
  77.  
  78.             case kSoundComponentSetOutputSelect:
  79.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentSetOutput);
  80.                 break;
  81.  
  82.             default:
  83.                 result = badComponentSelector;
  84.                 break;
  85.         }
  86.     else                                                    // selectors that can be delegated
  87.         switch (selector)
  88.         {
  89.             case kSoundComponentGetInfoSelect:
  90.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentGetInfo);
  91.                 break;
  92.  
  93.             case kSoundComponentStopSourceSelect:
  94.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentStopSource);
  95.                 break;
  96.  
  97.             case kSoundComponentPlaySourceBufferSelect:
  98.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentPlaySourceBuffer);
  99.                 break;
  100.  
  101.             default:
  102.                 result = DelegateComponentCall(params, globals->sourceComponent);
  103.                 break;
  104.         }
  105.  
  106.     return (result);
  107. }
  108.  
  109.  
  110. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. static pascal ComponentResult __SoundComponentCanDo(void *unused1, short selector)
  112. {
  113. #pragma unused (unused1)
  114.  
  115.     ComponentResult        result;
  116.  
  117.     switch (selector)
  118.     {
  119.         case kComponentRegisterSelect:
  120.         case kComponentVersionSelect:
  121.         case kComponentCanDoSelect:
  122.         case kComponentCloseSelect:
  123.         case kComponentOpenSelect:
  124.         case kSoundComponentSetSourceSelect:
  125.         case kSoundComponentGetSourceSelect:
  126.         case kSoundComponentGetSourceDataSelect:
  127.         case kSoundComponentSetOutputSelect:
  128.         // selectors that can be delegated
  129.         case kSoundComponentGetInfoSelect:
  130.         case kSoundComponentStopSourceSelect:
  131.         case kSoundComponentPlaySourceBufferSelect:
  132.             result = true;
  133.             break;
  134.  
  135.         default:
  136.             result = false;
  137.             break;
  138.     }
  139.  
  140.     return (result);
  141. }
  142.  
  143.